package com.example.librarymanagementproject2.converter;

import com.example.librarymanagementproject2.model.document.BookDocument;
import com.example.librarymanagementproject2.model.entity.Book;
import com.example.librarymanagementproject2.model.entity.BookCategory;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * @InterfaceName BookConverter
 * @Description 图书转换器
 * @Author Kx
 * @Date 2025/10/27 19:44
 * @Version 1.0
 */
@Mapper(componentModel = "spring")
public interface BookConverter {

    /**
     * @author: kx
     * @date: 2025/10/27 20:02
     * @param book : 图书信息
     * @param bookCategory : 图书分类信息
     * @return com.example.librarymanagementproject2.model.document.BookDocument
     * @description: 将图书信息转换为图书文档信息
    */
    @Mappings({
            @Mapping(source = "book.id", target = "id"),
            @Mapping(source = "bookCategory.name", target = "categoryName"),
            @Mapping(source = "book.title", target = "bookName"),
            @Mapping(source = "book.author", target = "author"),
            @Mapping(source = "book.publisher", target = "publisher"),
            @Mapping(source = "book.description", target = "description"),
            @Mapping(source = "book.coverUrl", target = "coverUrl"),
            @Mapping(source = "book.totalNum", target = "totalNum"),
            @Mapping(source = "book.status", target = "status")
    })
    BookDocument bookToBookDocument(Book book, BookCategory bookCategory);

}
